Convert GPWPT to use new parsing scheme.
authorRobert Lipe <robertlipe@gpsbabel.org>
Wed, 16 Sep 2015 03:43:28 +0000 (22:43 -0500)
committerRobert Lipe <robertlipe@gpsbabel.org>
Wed, 16 Sep 2015 03:43:28 +0000 (22:43 -0500)
nmea.cc

diff --git a/nmea.cc b/nmea.cc
index 14631ebbc42b2291f00c6b20d014cac6a0994437..b91c488d02f5e5822d9b9bce7def065d0af77b5f 100644 (file)
--- a/nmea.cc
+++ b/nmea.cc
@@ -624,26 +624,29 @@ gprmc_parse(char* ibuf)
 static void
 gpwpl_parse(char* ibuf)
 {
-  double latdeg, lngdeg;
-  char latdir, lngdir;
-  char sname[99];
-
-  sscanf(ibuf,"$%*2cWPL,%lf,%c,%lf,%c,%98[^*]",
-         &latdeg,&latdir,
-         &lngdeg,&lngdir,
-         sname);
+  QStringList fields = QString(ibuf).split(",", QString::KeepEmptyParts);
 
-  Waypoint* waypt = new Waypoint;
+  double latdeg = 0;
+  if (fields.size() > 1) latdeg = fields[1].toDouble();
+  QChar latdir = 'N';
+  if (fields.size() > 2) latdir = fields[2][0];
+  double lngdeg = 0;
+  if (fields.size() > 3) lngdeg = fields[3].toDouble();
+  QChar lngdir = 'E';
+  if (fields.size() > 4) lngdir = fields[4][0];
+  QString sname;
+  if (fields.size() > 5) sname = fields[5];
 
   if (latdir == 'S') {
     latdeg = -latdeg;
   }
-  waypt->latitude = ddmm2degrees(latdeg);
   if (lngdir == 'W') {
     lngdeg = -lngdeg;
   }
-  waypt->longitude = ddmm2degrees(lngdeg);
 
+  Waypoint* waypt = new Waypoint;
+  waypt->latitude = ddmm2degrees(latdeg);
+  waypt->longitude = ddmm2degrees(lngdeg);
   waypt->shortname = sname;
 
   curr_waypt = NULL; /* waypoints won't be updated with GPS fixes */